<?php


namespace app\controller;

use app\exception\BusinessException;
use app\service\OrderService;
use think\Request;
use think\facade\Validate;

class OrderController extends BaseController
{
    protected $orderService;

    public function __construct(OrderService $orderService)
    {
        $this->orderService = $orderService;
    }

    /**
     * 查询订单
     * @return json
     */
    public function search(Request $request)
    {
        $userId = $request->param('userId');
        $param = $request->param();
        $validate = Validate::rule([
            'status|订单状态' => 'require|number|min:0',
            'page|页码' => 'require|number|min:1',
            'size|条数' => 'require|number|min:1',
        ]);
        if (!$validate->check($param)) {
            throw new BusinessException(403,$validate->getError());
        }

        $res = $this->orderService->searchOrderList($userId,$param);

        return $this->renderJson($res);
    }

}